/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.jmx.action;

import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Properties;

/**
 *
 * @author Administrator
 */
public class PropertyManager implements PropertyManagerMBean {

    private Properties props = null;

    public PropertyManager(String path) {

        try {

            //load supplied property file    

            props = new Properties();

            FileInputStream f = new FileInputStream(path);

            props.load(f);

            f.close();

        }
        catch (Exception e) {

            e.printStackTrace();

        }

    }

    @Override
    public String getProperty(String key) {
        return props.getProperty(key);
    }

    @Override
    public void setProperty(String key, String value) {
        props.setProperty(key, value);
    }

    @Override
    public Enumeration keys() {
        return props.keys();
    }

    @Override
    public void setSource(String path) {
        try {

            props = new Properties();

            FileInputStream f = new FileInputStream(path);

            props.load(f);

            f.close();

        }
        catch (Exception e) {

            e.printStackTrace();

        }
    }
}
